#!/bin/bash

echo "=== 快速串口检测 ==="
echo ""

# 快速检测所有串口设备
echo "1. 所有串口设备:"
echo "=================="
find /dev -name "tty*" -type c 2>/dev/null | grep -E "(S|USB|AMA|ACM|XR|MX)" | sort
echo "=================="
echo ""

# 检测可用的串口
echo "2. 可用的串口设备:"
echo "=================="
for device in $(find /dev -name "tty*" -type c 2>/dev/null | grep -E "(S|USB|AMA|ACM|XR|MX)" | sort); do
    if stty -F "$device" 2>/dev/null; then
        echo "✓ $device (可用)"
    else
        echo "✗ $device (不可用)"
    fi
done
echo "=================="
echo ""

# 统计信息
echo "3. 统计信息:"
echo "=================="
total=$(find /dev -name "tty*" -type c 2>/dev/null | grep -E "(S|USB|AMA|ACM|XR|MX)" | wc -l)
available=$(find /dev -name "tty*" -type c 2>/dev/null | grep -E "(S|USB|AMA|ACM|XR|MX)" | while read device; do
    stty -F "$device" 2>/dev/null && echo "1"
done | wc -l)

echo "总串口设备: $total"
echo "可用串口设备: $available"
echo "不可用串口设备: $((total - available))"
echo "=================="
echo ""

# 推荐虚拟串口命名
echo "4. 推荐虚拟串口命名:"
echo "=================="
echo "安全命名 (推荐):"
echo "  ttyV0, ttyV1, ttyV2, ..."
echo "  virtual_serial1, virtual_serial2, ..."
echo "  my_serial1, my_serial2, ..."
echo ""
echo "避免使用:"
echo "  ttyS*, ttyUSB*, ttyAMA*, ttyACM*"
echo "==================" 